<template>
	<view>
		<view class="content">
			<u-form class="form-edit" :model="form" ref="uForm"
				:labelStyle="{fontSize: '28rpx', color: 'rgba(0, 0, 0, 0.8)'}">
				<view class="bg-white">
					<u-form-item label="商品名称" borderBottom label-width="70" required>
						<u--input v-model="form.name" inputAlign="right" placeholder="请输入商品名称" border="none"
							maxlength="30"></u--input>
					</u-form-item>
					<u-form-item label="商品条码" label-width="70" borderBottom>
						<view style="display: flex;align-items: center;">
							<view class="text-blue" @click="isGenerated">{{form.barCodeStatus?'自动':'关闭'}}</view>
							<u--input v-model="form.barCode" type="number" inputAlign="right" placeholder="保存时自动分配"
								border="none" maxlength="40"></u--input>
							<view class="u-p-l-10" @click="qRCodeAdd">
								<u-icon name="scan" color="#00000042" size="24" class="scan"></u-icon>
							</view>
						</view>
					</u-form-item>
					<u-form-item label="商品分组" label-width="70" borderBottom required @click="routing">
						<view style="display: flex;align-items: center;">
							<u--input v-model="form.commodityGroups.name" input-align="right" disabled
								disabledColor="#ffffff" placeholder="请选择" border="none"></u--input>
							<view class="u-p-l-10">
								<u-icon slot="right" name="arrow-right"></u-icon>
							</view>
						</view>
					</u-form-item>
					<u-form-item borderBottom>
						<view style="display: flex;justify-content: space-between;">
							<view class="font-8-28">图片(选填)</view>
							<u-upload :fileList="fileList1" @afterRead="afterRead" @delete="deleteByFileNameToFTP()"
								name="1" multiple :maxCount="1" :previewFullImage="true"></u-upload>
						</view>

					</u-form-item>
					<u-form-item borderBottom>
						<view style="display: flex;justify-content: space-between;">
							<view class="font-8-28">商品详细图片(选填)</view>
							<u-upload :fileList="fileList2" @afterRead="afterRead2" @delete="deleteByDetailFileNameToFTP()"
								name="2" multiple :maxCount="1" :previewFullImage="true"></u-upload>
						</view>
					
					</u-form-item>
					<u-form-item label="商品规格" label-width="70" borderBottom>
						<u--input v-model="form.spec" maxlength="10" inputAlign="right" placeholder="如红色，大码，大杯"
							border="none"></u--input>
					</u-form-item>
					<u-form-item borderBottom>
						<view class="display-flex">
							<view class="font-8-28">描述</view>
							<u--textarea v-model="form.desc" placeholder="非必填项,字数控制在50字以内" height="60" maxlength="50"
								border="none"></u--textarea>
						</view>
					</u-form-item>
					<u-form-item label="默认售价" label-width="70" required borderBottom>
						<view style="display: flex;align-items: center">
							<u--input v-model="form.retailPrice" @input="checkRetailPrice" type="digit"
								inputAlign="right" placeholder="请输入默认售价" maxlength="7" border="none">
							</u--input>
							<text class="u-p-l-20 font-8-28">元</text>
						</view>
					</u-form-item>
					<u-form-item label="会员售价" label-width="70" required borderBottom>
						<view style="display: flex;align-items: center">
							<u-icon slot="left" name="question-circle" @click="retailVIPPriceTip=true" size="28" :stop="true"/>

							<u--input v-model="form.retailVIPPrice" @input="checkRetailVIPPrice" type="digit"
								inputAlign="right" placeholder="请输入会员售价" maxlength="7" border="none">
							</u--input>
							<text class="u-p-l-20 font-8-28">元</text>
						</view>
					</u-form-item>
					<u-form-item label="成本价格" label-width="70" borderBottom>
						<view style="display: flex;align-items: center">
							<u--input v-model="form.costPrice" @input="checkCostPrice" type="digit" inputAlign="right"
								placeholder="请输入成本价格" maxlength="7" border="none">
							</u--input>
							<text class="u-p-l-20 font-8-28">元</text>
						</view>
					</u-form-item>
					<u-form-item label="开启严格库存" label-width="120" borderBottom>
						<view style="display: flex;align-items: flex-end;justify-content: flex-end;">
							<u-switch @change="form.strictInventoryManagement=!form.strictInventoryManagement"
								:value="form.strictInventoryManagement" activeColor="#6072FF">
							</u-switch>
						</view>
					</u-form-item>
					<u-form-item label="纳入售币营业额" label-width="120" borderBottom>
						<view style="display: flex;align-items: flex-end;justify-content: flex-end;">
							<u-switch @change="form.includeCoinSalesTurnover=!form.includeCoinSalesTurnover"
								:value="form.includeCoinSalesTurnover" activeColor="#6072FF">
							</u-switch>
						</view>
					</u-form-item>

					<u-form-item borderBottom>
						<view class="item-top-box">
							<view class="font-8-28">兑换价格</view>
							<u-switch @change="form.openExchange=!form.openExchange" :value="form.openExchange"
								activeColor="#6072FF">
							</u-switch>
						</view>
						<view class="item-container" v-if="form.openExchange">
							<view class="item-box" style="margin-top: 48rpx;">
								<view class="label-color">积分兑换</view>
								<u--input type="number" @input="integerTest($event,1)"
									v-model="form.integralConversionPrice" inputAlign="right" placeholder="请输入积分兑换价格"
									maxlength="6" border="none"></u--input>
								<text class="u-p-l-20 font-8-28">积分</text>
							</view>
							<view class="item-box">
								<view class="label-color">彩票兑换</view>
								<u--input type="number" @input="integerTest($event,2)"
									v-model="form.lotteryConversionPrice" inputAlign="right" placeholder="请输入彩票兑换价格"
									maxlength="6" border="none"></u--input>
								<text class="u-p-l-20 font-8-28">彩票</text>
							</view>
							<view class="item-box">
								<view class="label-color">游戏币兑换</view>
								<u--input type="number" @input="integerTest($event,3)"
									v-model="form.coinConversionPrice" inputAlign="right" placeholder="请输入游戏币兑换价格"
									maxlength="6" border="none"></u--input>
								<text class="u-p-l-20 font-8-28">币</text>
							</view>
							<view class="display-flex">
								<view class="hint">注意：输入0或留空，则表示不参与该项兑换</view>
							</view>
						</view>
					</u-form-item>
					<u-form-item borderBottom>
						<view class="item-top-box">
							<view class="font-8-28">开启回收</view>
							<u-switch @change="form.openRecovery=!form.openRecovery" :value="form.openRecovery">
							</u-switch>
						</view>
						<view class="item-box" style="margin-top: 48rpx;" v-if="form.openRecovery">
							<view class="label-color">积分回收</view>
							<u--input type="number" @input="integerTest($event,4)" v-model="form.recoveryPrice"
								inputAlign="right" placeholder="请输入回收价格" border="none" maxlength="6"></u--input>
							<text class="u-p-l-20 font-8-28">积分</text>
						</view>
					</u-form-item>
					<u-form-item label="上架终端" label-width="70" required borderBottom>
						<view style="display: flex;">
							<u-checkbox-group inactiveColor="#6072FF" :value="checkboxValue1">
								<u-checkbox :checked="form.posTerminal" :customStyle="{marginBottom: '8px'}"
									@change="checkboxChangePos($event)" label="收银系统">
								</u-checkbox>
								<u-checkbox :checked="form.integralMallTerminal" :customStyle="{marginBottom: '8px'}"
									@change="checkboxChangeApplets($event)" label="小程序积分商城">
								</u-checkbox>
							</u-checkbox-group>
						</view>
					</u-form-item>
					<u-form-item borderBottom v-if="form.integralMallTerminal">
						<u-form-item label="领取方式" label-width="80">
							<view style="display: flex;">
								<view class="u-m-r-30">
									<u-checkbox-group>
										<u-checkbox :checked="form.isSelfMention" @change="isSelfMentionChange($event)"
											v-model="form.isSelfMention" inactiveColor="#6072FF"
											label="到店自提"></u-checkbox>
									</u-checkbox-group>
								</view>
								<view>
									<u-checkbox-group>
										<u-checkbox @change="isDirectMailChange($event)" :checked="form.isDirectMail"
											v-model="form.isDirectMail" inactiveColor="#6072FF" label="快递包邮">
										</u-checkbox>
									</u-checkbox-group>
								</view>
							</view>
						</u-form-item>
					</u-form-item>

					<u-form-item label="上架门店" label-width="100">
					</u-form-item>
					<view>
						<u-checkbox-group size="20" iconPlacement="right" v-model="form.merchantStoreIdList"
							placement="column">
							<u-checkbox :customStyle="{marginBottom: '16px'}" v-for="(item, index) in checkboxList"
								:key="index" :label="item.storeName" :name="item.merchantStoreId">
							</u-checkbox>
						</u-checkbox-group>
					</view>
					<view style="height:50rpx"></view>
				</view>
			</u-form>
		</view>
		<view class="footer" id="footer">
			<view class="u-m-b-40 u-m-l-30 u-m-r-30">
				<u-button color="rgb(96,114,255);" shape="circle" @click="saveGoods()">保存</u-button>
			</view>
		</view>


		<u-modal :show="retailVIPPriceTip" content="普通会员储值余额后成为正式会员,在收银台结算时使用“余额支付”即可享受会员价" confirm-text="确定"
			@confirm="retailVIPPriceTip=false" @cancel="retailVIPPriceTip=false" />

	</view>
</template>

<script>
	export default {
		data() {
			return {
				checkboxList: [],
				leftIconStyle: {
					color: '#ff0000',
				},
				checkboxValue1: [],
				height: 0,
				headerHeight: 0,
				footerHeight: 0,
				title: '添加商品',
				form: {
					//会员售价
					retailVIPPrice: '',
					//是否自动生成条形码
					barCodeStatus: true,
					//商品id
					id: '',
					//商品名称
					name: '',
					//商品条码
					barCode: '',
					//商品分组id
					commodityGroupId: -1,
					//商品图片
					fileName: '',
					//商品详细图片
					commodityDetailFileName: '',
					//商品规格
					spec: '',
					//描述
					desc: '',
					//默认售价
					retailPrice: '',
					//成本价格
					costPrice: '',
					//纳入售币营业额
					includeCoinSalesTurnover: false,
					//严格库存管理
					strictInventoryManagement: false,
					//开启兑换
					openExchange: false,
					//积分兑换
					integralConversionPrice: '',
					//彩票兑换
					lotteryConversionPrice: '',
					//游戏币兑换
					coinConversionPrice: '',
					//开启回收
					openRecovery: false,
					//回收价格
					recoveryPrice: '',
					//上架 小程序积分商城
					integralMallTerminal: false,
					//上架 POS端
					posTerminal: false,
					//选中的商品分组
					commodityGroups: {},
					//选中的上架门店
					stores: [],
					//是否自提
					isSelfMention: false,
					//是否直邮
					isDirectMail: false,
					//上架门店
					merchantStoreIdList: []
				},
				uploadUrl: this.$configPath.uploadImage + '/api/upload/uploadImageToFTP',
				header: {
					Authorization: ''
				},
				//上架门店显示的值
				storeName: '',
				// 商品图片
				fileList1: [],
				// 商品详细图片
				fileList2: [],
				default: {
					//会员售价
					retailVIPPrice: '',
					//默认售价
					retailPrice: '',
					//积分兑换
					integralConversionPrice: '',
					//彩票兑换
					lotteryConversionPrice: '',
					//游戏币兑换
					coinConversionPrice: '',
					//回收价格
					recoveryPrice: '',
					//开启回收
					openRecovery: '',
					//开启积分兑换
					openExchange: '',
					//是否自提
					isSelfMention: false,
					//是否直邮
					isDirectMail: false,
					//上架 小程序积分商城
					integralMallTerminal: false,
					//上架 POS端
					posTerminal: false,
				},
				//选中的商品分组
				commodityGroups: {},
				//选中的架门店
				commodityStoreUpDownStoreList: [],
				// 商品
				commodity: {},
				$commodityTypeTypeEnum: this.$commodityTypeTypeEnum,
				storageKeyEnum: this.$storageKeyEnum,
				retailVIPPriceTip: false,
			}
		},
		onReady() {
			this.getPomHeight();
		},
		onLoad(option) {

			this.header.Authorization = 'Bearer ' + this.storageKeyEnum.token_cache;
			this.findStore();
			if (option.commodity) {
				uni.setNavigationBarTitle({
					title: '编辑商品'
				})
				this.commodity = JSON.parse(option.commodity)
				this.findByIdCommodityVo(this.commodity.id)
			} else {
				uni.setNavigationBarTitle({
					title: '添加商品'
				})

				this.findDefaultCommodityGroup();
			}
			//扫条码查询公共库是否存在商品
			if (option.barCode) {
				console.log(option.barCode)
				this.findOneCommodityInfoCommon(option.barCode)
			}
		},
		watch: {
			'commodityStoreUpDownStoreList': {
				handler(newVal, oldVal) {
					if (newVal.length === 1) {
						this.storeName = newVal[0].storeName;
					} else if (newVal.length > 1) {
						this.storeName = '选择了' + newVal.length + '个门店';
					} else {
						this.storeName = '';
					}
					this.form.stores = newVal;
				},
				deep: true, // 开启对象深度监听
			},
			'commodityGroups': {
				handler(newVal, oldVal) {
					this.form.commodityGroups = newVal;
				},
				deep: true, // 开启对象深度监听
			}
		},
		methods: {
			findOneCommodityInfoCommon(barCode) {
				let param = {
					barCode: barCode,
				}
				this.$api('commodityInfoCommon.findOneCommodityInfoCommon', param).then(res => {
					if (res.status == 0) {
						console.log(res.data)
						try {
							this.form.name = res.data.name;
							this.form.barCode = res.data.barCode;
							this.form.fileName = res.data.fileName;
							if (this.form.fileName) {
								this.fileList1.push({
									url: this.$configPath.imgURL + '/' + this.form.fileName
								});
							}
							// this.afterRead(fileName)
							this.form.spec = res.data.spec
							this.form.desc = res.data.classification
						} catch (e) {
							console.error(e.toString())
							getApp().err("初始化数据不成功：" + e.toString());
						} finally {
							uni.hideLoading()
						}
					} else {
						getApp().err(res.msg);
					}
				})
			},
			isGenerated() {
				this.form.barCodeStatus = !this.form.barCodeStatus;
			},
			findStore() {
				this.$api('merchantStore.findStoreShelves', {}).then(res => {
					if (res.status == 0) {
						this.checkboxList = res.data;
					} else {
						this.$helpers.toast('请求数据失败:' + res.msg);
					}
				})
			},
			findDefaultCommodityGroup() {

				const param = {
					type: 2
				}
				this.$api('commodityGroup.getDefaultCommodityGroup', param).then(res => {
					if (res.status == 0) {
						if (!this.$u.test.isEmpty(res.data)) {
							this.form.commodityGroups = res.data
						}
					} else {
						getApp().err('加载默认分组不成功:' + res.msg);
					}
				})
			},

			findByIdCommodityVo(id) {
				uni.showLoading({
					title: '加载中...',
					mask: true
				})
				const param = {
					id: id
				}
				this.$api('commodity.findByIdCommodityVo', param).then(res => {
					if (res.status == 0) {
						try {
							this.form.id = res.data.id;
							this.form.name = res.data.name;
							this.form.barCode = res.data.barCode;
							this.form.commodityGroups = res.data.commodityGroupVo;
							this.form.fileName = res.data.fileName;
							this.form.commodityDetailFileName = res.data.commodityDetailFileName;
							this.form.spec = res.data.spec
							this.form.desc = res.data.desc
							this.form.retailPrice = res.data.retailPrice;
							this.form.costPrice = res.data.costPrice;
							this.form.strictInventoryManagement = res.data.strictInventoryManagement;
							this.form.includeCoinSalesTurnover = res.data.includeCoinSalesTurnover;

							this.form.openExchange = res.data.openExchange
							this.form.integralConversionPrice = res.data.integralConversionPrice
							this.form.lotteryConversionPrice = res.data.lotteryConversionPrice
							this.form.coinConversionPrice = res.data.coinConversionPrice

							this.form.openRecovery = res.data.openRecovery
							this.form.recoveryPrice = res.data.recoveryPrice

							this.form.integralMallTerminal = res.data.integralMallTerminal
							this.form.posTerminal = res.data.posTerminal

							this.form.stores = res.data.commodityStoreUpDownList;

							this.form.isSelfMention = res.data.isSelfMention;
							this.form.isDirectMail = res.data.isDirectMail;
							this.form.retailVIPPrice = res.data.retailVIPPrice;
							if (this.form.fileName) {
								this.fileList1.push({
									url: this.$configPath.imgURL + '/' + this.form.fileName
								});
							}
						  if (this.form.commodityDetailFileName) {
							this.fileList2.push({
							  url: this.$configPath.imgURL + '/' + this.form.commodityDetailFileName
							});
						  }
							this.commodityGroups = res.data.commodityGroup;

							this.form.merchantStoreIdList = []
							res.data.commodityStoreUpDownList.forEach(data => {
								this.form.merchantStoreIdList.push(data.merchantStoreId)
							})
						} catch (e) {
							console.error(e.toString())
							getApp().err("初始化数据不成功：" + e.toString());
						} finally {
							uni.hideLoading()
						}
					} else {
						uni.hideLoading()
						getApp().err('加载不成功:' + res.msg);
					}
				})
			},
			//是否自提
			isSelfMentionChange(e) {
				this.form.isSelfMention = e
			},
			//是否直邮
			isDirectMailChange(e) {
				this.form.isDirectMail = e
			},
			saveGoods() {
				if (uni.$u.test.isEmpty(this.form.name)) {
					this.$helpers.toast('商品名称不能为空');
					return;
				}
				if (uni.$u.test.isEmpty(this.form.commodityGroups)) {
					this.$helpers.toast('请选择商品分组');
					return;
				}
				if (this.$u.test.isEmpty(this.form.retailPrice)) {
					this.$helpers.toast('请输入默认售价');
					return;
				}
				if (this.$u.test.isEmpty(this.form.retailVIPPrice)) {
					this.$helpers.toast('请输入会员售价');
					return;
				}
				if (!this.form.posTerminal && !this.form.integralMallTerminal) {
					this.$helpers.toast('请至少选择一项上架终端');
					return;
				}
				// if (!this.form.isSelfMention && !this.form.isDirectMail) {
				// 	this.$helpers.toast('请至少选择一项邮寄方式');
				// 	return;
				// }
				//关闭积分兑换 赋值为空
				if (!this.form.openExchange) {
					this.form.integralConversionPrice = ''
					this.form.lotteryConversionPrice = ''
					this.form.coinConversionPrice = ''
				}
				//关闭回收也赋值为''
				if (!this.form.openRecovery) {
					this.form.recoveryPrice = ''
				}
				uni.showLoading({
					title: '请求中',
					mask: true
				})
				this.form.commodityGroupId = this.form.commodityGroups.id;
				this.$api('commodity.saveProduct', this.form).then(res => {
					if (res.status == 0) {
						uni.hideLoading();
						const that = this;
						this.$helpers.toast('保存成功', 'success', 2000, true, () => {
							uni.navigateBack()
						});
					} else {
						this.$helpers.toast('修改失败：' + res.msg);
					}
				})
			},
			checkboxChangePos(n) {
				this.form.posTerminal = n;
			},

			checkboxChangeApplets(n) {
				this.form.integralMallTerminal = n;
			},

			integerTest(e, index) {
				//正则表达试
				e = (e.match(/^(?!0\d)\d+$/)) || ''
				//重新赋值给input
				this.$nextTick(() => {
					if (index == 1) {
						this.form.integralConversionPrice = e == '' ? e : e[0]
					} else if (index == 2) {
						this.form.lotteryConversionPrice = e == '' ? e : e[0]
					} else if (index == 3) {
						this.form.coinConversionPrice = e == '' ? e : e[0]
					} else {
						this.form.recoveryPrice = e == '' ? e : e[0]
					}
				})
			},

			checkRetailPrice(e) {
				if (e == '.') {
					this.$helpers.toast('请输入以数字开头的售价');
					this.$nextTick(() => {
						this.form.retailPrice = '';
					});
					return
				}

				//正则表达试
				e = (e.match(/^\d*(\.?\d{0,2})/g)[0]) || ''
				//重新赋值给input
				this.$nextTick(() => {
					this.form.retailPrice = e
				})
			},

			checkRetailVIPPrice(e) {
				if (e == '.') {
					this.$helpers.toast('请输入以数字开头的售价');
					this.$nextTick(() => {
						this.form.retailVIPPrice = '';
					});
					return
				}

				//正则表达试
				e = (e.match(/^\d*(\.?\d{0,2})/g)[0]) || ''
				//重新赋值给input
				this.$nextTick(() => {
					this.form.retailVIPPrice = e
				})
			},
			checkCostPrice(e) {
				if (e == '.') {
					this.$helpers.toast('请输入以数字开头的成本价');
					this.$nextTick(() => {
						this.form.costPrice = '';
					});
					return
				}

				//正则表达试
				e = (e.match(/^\d*(\.?\d{0,2})/g)[0]) || ''
				//重新赋值给input
				this.$nextTick(() => {
					this.form.costPrice = e
				})
			},
			// 新增图片
			async afterRead(event) {
				// 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = event.file
				console.log(lists)
				console.log(event.name)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				let _this = this;
				for (let i = 0; i < lists.length; i++) {
					uni.compressImage({
						src: lists[i].url,
						quality: 30, // 越小质量越不好，但压缩率就更高
						success: async res => {
							const result = await _this.uploadFilePromise(res.tempFilePath)
							if (!this.$u.test.isEmpty(result)) {
								this.form.fileName = result;
								// console.log("图片名称：", this.$configPath.imgURL + result);
								let item = this[`fileList${event.name}`][fileListLen]
								this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
									status: 'success',
									message: '',
									url: result
								}))
								fileListLen++
							}
						}
					})
				}
			},

// 新增图片
			async afterRead2(event) {
				// 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = event.file
				console.log(lists)
				console.log(event.name)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				let _this = this;
				for (let i = 0; i < lists.length; i++) {
					uni.compressImage({
						src: lists[i].url,
						quality: 30, // 越小质量越不好，但压缩率就更高
						success: async res => {
							const result = await _this.uploadFilePromise(res.tempFilePath)
							if (!this.$u.test.isEmpty(result)) {
								this.form.commodityDetailFileName = result;
								// console.log("图片名称：", this.$configPath.imgURL + result);
								let item = this[`fileList${event.name}`][fileListLen]
								this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
									status: 'success',
									message: '',
									url: result
								}))
								fileListLen++
							}
						}
					})
				}
			},
			uploadFilePromise(fileUrl) {
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: this.$configPath.baseURL + '/api/upload/uploadImageToFTP',
						filePath: fileUrl,
						name: 'image',
						header: {
							Authorization: 'Bearer ' + this.$store.getters.GET_VALUE("GET_TOKEN")
						},
						/* 会与全局header合并，如有同名属性，局部覆盖全局 */
						timeout: 6000,
						formData: {
							user: 'test'
						},
						success: (res) => {
							let data = JSON.parse(res.data);
							if (data.status == 0) {
								setTimeout(() => {
									resolve(data.data.keyRes);
									this.$helpers.toast("上传成功");
								}, 1000)
							} else {
								if (uni.$u.test.isEmpty(data.msg)) {
									this.$helpers.toast("图片上传失败");
								} else {
									this.$helpers.toast(data.msg);
								}
								this.deleteByFileNameToFTP();
							}
						},
						fail: (res) => {
							let errMsg = res.errMsg;
							if (uni.$u.test.contains(errMsg, 'timeout')) {
								errMsg = "请求超时，请重新上传";
							}
							this.deleteByFileNameToFTP();
							this.$helpers.toast(errMsg);
						},
					});
				})
			},

			// 删除已上传的图片
			deleteByFileNameToFTP() {
				this.form.fileName = '';
				this.fileList1 = [];
				this.$helpers.toast("删除成功");
			},
			// 删除已上传的图片
			deleteByDetailFileNameToFTP() {
				this.form.commodityDetailFileName = '';
				this.fileList2 = [];
				this.$helpers.toast("删除成功");
			},

			selectStore() {

				// console.log("this.form.id:", this.form.id)

				// 默认售价
				this.default.retailPrice = this.form.retailPrice;
				// 开启回收
				this.default.recoveryPrice = this.form.recoveryPrice;
				this.default.openRecovery = this.form.openRecovery;
				// 开启兑换
				this.default.openExchange = this.form.openExchange;
				this.default.integralConversionPrice = this.form.integralConversionPrice
				this.default.lotteryConversionPrice = this.form.lotteryConversionPrice
				this.default.coinConversionPrice = this.form.coinConversionPrice
				this.default.isSelfMention = this.form.isSelfMention
				this.default.isDirectMail = this.form.isDirectMail
				this.default.integralMallTerminal = this.form.integralMallTerminal;
				this.default.posTerminal = this.form.posTerminal;
				let url = '/pages-commodity/store-shelves?';
				//加个类别数字为2，标记是通用商品跳转上架门店
				url = url.concat('commodityType=' + this.$commodityTypeTypeEnum.GENERAL_GOODS)
				uni.navigateTo({
					url: url
				});
			},
			routing() {
				let id = uni.$u.test.isEmpty(this.form.commodityGroups) ? '' : this.form.commodityGroups.id;
				uni.navigateTo({
					url: '/pages-commodity/commodity-group?type=' + 2 +
						'&id=' + id
				});
			},
			// 获取各个盒子的高度
			getPomHeight() {
				const query = uni.createSelectorQuery().in(this);
				query.select('#footer').boundingClientRect(data => {
					this.footerHeight = data.height;
				}).exec();
				// 这里再加1是为了上拉触发下一页
				let h = uni.getSystemInfoSync().windowHeight;
				this.height = h - (this.headerHeight + this.footerHeight);
			},
			// 调用微信扫一扫
			qRCodeAdd() {

				uni.showLoading({
					title: "正在调起...",
					mask: true
				})
				var that = this;
				uni.scanCode({
					success: function(res) {
						uni.hideLoading();
						that.form.barCode = res.result;
					},
					fail(res) {
						console.error(res);
						uni.hideLoading();
						getApp().err("调起不成功：" + res.toString());
					}
				});
			},
			reachBottom() {

			}
		}
	}
</script>
<style lang="scss">
	page {
		background-color: #FFFFFF;
	}
</style>
<style lang="scss" scoped>
	.text-blue {
		color: #6072FF;
		margin-right: 60rpx;
	}

	.item-container {
		.hint {
			padding-left: 43rpx;
			color: rgb(255, 6, 6);
			font-size: 28rpx;
		}
	}

	.item-top-box {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.item-box {
		display: flex;
		justify-content: space-between;
		align-items: baseline;
		margin-bottom: 60rpx;
	}

	.display-flex {
		display: flex;
		justify-content: space-between;
	}

	.label-color {
		padding-left: 43rpx;
		color: #00000099;
	}

	.u-textarea {
		background: rgb(249, 249, 249) !important;
		border-radius: 10rpx;
	}

	/deep/ .u-textarea__field {

		background-color: #F9F9F9;
	}

	/deep/ .u-textarea {
		margin-left: 22rpx;
		padding: 0 !important;
	}

	/deep/ .u-checkbox-label--left {

		margin-right: 73rpx;
		margin-bottom: 0 !important;
	}

	/deep/ .u-upload {
		flex: 0 1 auto !important;
	}

	.u-icon__icon {
		font-size: 20px !important;
	}


	.content {
		padding: 30rpx;
		padding-bottom: 145rpx;

		.form-edit {
			.title {
				font-weight: bold;
			}

			.bg-white {}

			.separate {
				padding: 10rpx;
			}
		}
	}

	.font-8-28 {
		font-size: 28rpx;
		color: rgba(0, 0, 0, 0.8);
	}

	.slot-content {
		padding: $u-padding-large;
		text-align: center;
	}

	.footer {
		width: 100%;
		background-color: white;
		position: fixed;
		bottom: 0rpx;
		z-index: 100;
	}

	/deep/ .u-form-item__body {
		padding: 36rpx 0 !important;
	}

	/deep/ .u-input__content__field-wrapper__field {
		font-size: $f-base !important;
	}
</style>
